<template>
  <!-- 表格 -->
  <el-table :data="tableData"  border stripe style="width: 100%">
    <el-table-column type="index" label="序号" width="60" align="center">
    </el-table-column>
    <el-table-column prop="title" label="广告标题" align="center">
    </el-table-column>
    <el-table-column prop="imageUrl" label="广告图片" align="center">
      <template slot-scope="scope">
        <img :src="scope.row.imageUrl" alt="" />
      </template>
    </el-table-column>
    <el-table-column prop="advertUrl" label="广告链接" align="center">
    </el-table-column>
    <el-table-column prop="status" label="状态" align="center">
      <template slot-scope="scope">
        <el-tag :type="scope.row.status == 0 ? 'danger ' : 'success'">{{
          scope.row.status | IsUse
        }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column prop="sort" label="排序" align="center"> </el-table-column>
    <el-table-column label="操作" align="center">
      <template slot-scope="scope">
        <el-button size="mini" @click="editDialog(scope.row.id)"
          >编辑</el-button
        >
        <el-button size="mini" type="danger" @click="delItem(scope.row.id)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
let that;

export default {
  props: {
    tableData: Array,
    options: Array
  },
  methods: {
    // 删除
    delItem(id) {
      this.$emit("delItem", id);
    },
    // 编辑 dialog
    editDialog(id) {
      this.$emit("editDialog", id);
    }
  },
  filters: {
    // 状态过滤器
    IsUse(e) {
      return that.options.find(item => item.val == e).title;
    }
  },
  created() {
    // 为过滤器存储 this
    that = this;
  }
};
</script>

<style scoped>
img {
  width: 90px;
  height: 60px;
}
</style>
